package com.xiaoyu.tool.service.user;

import com.xiaoyu.tool.entity.User.User;
import com.xiaoyu.tool.entity.User.UserIntegral;
import com.xiaoyu.tool.repository.user.UserIntegralRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class UserIntegralService {

    @Autowired
    private UserIntegralRepository userIntegralRepository;


    public void save(UserIntegral userIntegral){
        userIntegralRepository.save(userIntegral);
    }

    public void createUserIntegral(User user){
        UserIntegral userIntegral = userIntegralRepository.findByUserId(user.getId());
        if (StringUtils.isEmpty(userIntegral)){
            userIntegral = new UserIntegral();
            userIntegral.setUserId(user.getId());
            userIntegralRepository.save(userIntegral);
        }
    }

}
